﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GalaSoft.MvvmLight;
using System.Windows.Input;
using GalaSoft.MvvmLight.Command;

namespace MvvmDialogBehaviorSample
{
    public class MainViewModel:ViewModelBase
    {
        public MainViewModel()
        {
        }

        private ViewModelBase _Dialog;
        public ViewModelBase Dialog
        {
            get { return _Dialog; }
            set
            {
                if (_Dialog != value)
                {
                    _Dialog = value;
                    RaisePropertyChanged("Dialog");
                }
            }
        }

        private ICommand _OpenDialogCommand;
        public ICommand OpenDialogCommand
        {
            get { 
                if (_OpenDialogCommand == null)
                {
                    _OpenDialogCommand = new RelayCommand(OpenDialog);
                }

                return _OpenDialogCommand;
            }
        }

        private void OpenDialog()
        {
            // Open Dialog
            Dialog = new LoginDialogViewModel(CloseDialog) { UserName="LastLoginUser1" };
        }

        private void CloseDialog()
        {
            // Close Dialog
            Dialog = null;
        }
    }
}
